import React, { useState } from 'react';
import { Form, Input, Button, Card, message } from 'antd';
import { UserOutlined, LockOutlined } from '@ant-design/icons';
import { useHistory } from 'react-router-dom';
import './style/login.scss';

const Login = () => {
  const [loading, setLoading] = useState(false);
  const history = useHistory();

  const onFinish = async (values) => {
    setLoading(true);
    try {
      // 模拟登录验证
      if (values.username === 'admin' && values.password === 'admin') {
        // 模拟用户信息
        const userInfo = {
          username: values.username,
          role: { name: 'admin', type: 'admin' },
          auth: []
        };
        
        localStorage.setItem('userInfo', JSON.stringify(userInfo));
        message.success('登录成功！');
        
        // 跳转到主页面
        history.push('/checkin/activity-management');
      } else {
        message.error('用户名或密码错误！');
      }
    } catch (error) {
      message.error('登录失败，请重试！');
    } finally {
      setLoading(false);
    }
  };

  return (
    <div className="login-container">
      <div className="login-content">
        <Card className="login-card">
          <div className="login-header">
            <h1>打卡系统</h1>
            <p>欢迎使用打卡管理系统</p>
          </div>
          
          <Form
            name="login"
            onFinish={onFinish}
            autoComplete="off"
            size="large"
          >
            <Form.Item
              name="username"
              rules={[{ required: true, message: '请输入用户名！' }]}
            >
              <Input
                prefix={<UserOutlined />}
                placeholder="用户名"
              />
            </Form.Item>

            <Form.Item
              name="password"
              rules={[{ required: true, message: '请输入密码！' }]}
            >
              <Input.Password
                prefix={<LockOutlined />}
                placeholder="密码"
              />
            </Form.Item>

            <Form.Item>
              <Button
                type="primary"
                htmlType="submit"
                loading={loading}
                className="login-button"
                block
              >
                登录
              </Button>
            </Form.Item>
          </Form>
          
          <div className="login-tips">
            <p>测试账号：admin / admin</p>
          </div>
        </Card>
      </div>
    </div>
  );
};

export default Login; 